﻿<UserControl x:Class="CodeIn.Modules.Ui.FileExplorer.FileExplorerView"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:local="clr-namespace:CodeIn.Modules.Ui.FileExplorer"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300"
		d:DesignWidth="300">

	<UserControl.Resources>
		<BitmapImage x:Key="icon_plus" UriSource="pack://application:,,,/resources/gfx/icon_fileexplorer_plus.png" />
		<BitmapImage x:Key="icon_minus" UriSource="pack://application:,,,/resources/gfx/icon_fileexplorer_minus.png" />
		<BitmapImage x:Key="icon_file" UriSource="pack://application:,,,/resources/gfx/icon_file.png" />
		<BitmapImage x:Key="icon_folder_closed" UriSource="pack://application:,,,/resources/gfx/icon_folder_closed.png" />
		<BitmapImage x:Key="icon_folder_opened" UriSource="pack://application:,,,/resources/gfx/icon_folder_opened.png" />
		<BitmapImage x:Key="icon_drive" UriSource="pack://application:,,,/resources/gfx/icon_drive.png" />
	</UserControl.Resources>

	<DockPanel>

		<TreeView ItemsSource="{Binding Roots}" BorderThickness="0">

			<!-- ******************************************************************
			**** ITEM TEMPLATE
			****************************************************************** -->
			<TreeView.ItemTemplate>
				<HierarchicalDataTemplate DataType="{x:Type local:FileExplorerItemViewModel}"
						ItemsSource="{Binding Children}">

					<!--VISUAL-->
					<DockPanel>
						<Image DockPanel.Dock="Left" Margin="0,0,5,0" Stretch="None" x:Name="icon"
								Source="{StaticResource icon_file}" />
						<TextBlock Text="{Binding Name}" VerticalAlignment="Center" />
					</DockPanel>

					<!--TRIGGERS-->
					<HierarchicalDataTemplate.Triggers>
						<MultiDataTrigger>
							<MultiDataTrigger.Conditions>
								<Condition Binding="{Binding Type}" Value="DIRECTORY" />
								<Condition Binding="{Binding IsExpanded}" Value="false" />
							</MultiDataTrigger.Conditions>
							<Setter TargetName="icon" Property="Source" Value="{StaticResource icon_folder_closed}" />
						</MultiDataTrigger>
						<MultiDataTrigger>
							<MultiDataTrigger.Conditions>
								<Condition Binding="{Binding Type}" Value="DIRECTORY" />
								<Condition Binding="{Binding IsExpanded}" Value="true" />
							</MultiDataTrigger.Conditions>
							<Setter TargetName="icon" Property="Source" Value="{StaticResource icon_folder_opened}" />
						</MultiDataTrigger>
						<DataTrigger Binding="{Binding Type}" Value="DRIVE">
							<Setter TargetName="icon" Property="Source" Value="{StaticResource icon_drive}" />
						</DataTrigger>
					</HierarchicalDataTemplate.Triggers>

				</HierarchicalDataTemplate>
			</TreeView.ItemTemplate>

			<!-- ******************************************************************
			**** ITEM CONTAINER STYLE
			****************************************************************** -->
			<TreeView.ItemContainerStyle>
				<Style TargetType="{x:Type TreeViewItem}">
					<EventSetter Event="MouseRightButtonDown" Handler="OnItemMouseRightButtonDown" />
					<EventSetter Event="MouseDoubleClick" Handler="OnItemMouseDoubleClick" />
					<EventSetter Event="Selected" Handler="OnItemSelected" />
					<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
					<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
					<Setter Property="ContextMenu" Value="{Binding ContextMenu}" />
					<Setter Property="Margin" Value="0,0,0,2" />
					<Setter Property="Template">
						<Setter.Value>
							<ControlTemplate TargetType="{x:Type TreeViewItem}">
								
								<!--Visual-->
								<StackPanel>
									<DockPanel Background="Transparent">
										<Image x:Name="icon" Source="{StaticResource icon_minus}" Margin="0,0,0,0"
												Stretch="None" VerticalAlignment="Center"
												RenderOptions.EdgeMode="Aliased" MouseDown="OnIconMouseDown" />
										<Border x:Name="border" BorderThickness="1" BorderBrush="Transparent"
												Background="Transparent" CornerRadius="3" Padding="2,0,2,0"
												HorizontalAlignment="Left">
											<ContentPresenter x:Name="PART_Header" ContentSource="Header" />
										</Border>
									</DockPanel>
									<ItemsPresenter x:Name="items" Margin="20,0,0,0" />
								</StackPanel>

								<!--Triggers-->
								<ControlTemplate.Triggers>
									<DataTrigger Binding="{Binding Type}" Value="FILE">
										<Setter TargetName="icon" Property="Visibility" Value="Hidden" />
									</DataTrigger>
									<Trigger Property="IsExpanded" Value="false">
										<Setter TargetName="items" Property="Visibility" Value="Collapsed" />
										<Setter TargetName="icon" Property="Source" Value="{StaticResource icon_plus}" />
									</Trigger>
									<MultiDataTrigger>
										<MultiDataTrigger.Conditions>
											<Condition Binding="{Binding IsSelected}" Value="true" />
											<Condition
													Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeView}}"
													Value="true" />
										</MultiDataTrigger.Conditions>
										<Setter TargetName="border" Property="BorderBrush" Value="#84ACDD" />
										<Setter TargetName="border" Property="Background">
											<Setter.Value>
												<LinearGradientBrush EndPoint="0,1">
													<GradientStop Offset="0" Color="#ECF5FF" />
													<GradientStop Offset="1" Color="#D0E5FF" />
												</LinearGradientBrush>
											</Setter.Value>
										</Setter>
									</MultiDataTrigger>
									<MultiDataTrigger>
										<MultiDataTrigger.Conditions>
											<Condition Binding="{Binding IsSelected}" Value="true" />
											<Condition
													Binding="{Binding IsKeyboardFocusWithin, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TreeView}}"
													Value="false" />
										</MultiDataTrigger.Conditions>
										<Setter TargetName="border" Property="BorderBrush" Value="#888" />
										<Setter TargetName="border" Property="Background">
											<Setter.Value>
												<LinearGradientBrush EndPoint="0,1">
													<GradientStop Offset="0" Color="#F9F9F9" />
													<GradientStop Offset="1" Color="#E6E6E6" />
												</LinearGradientBrush>
											</Setter.Value>
										</Setter>
									</MultiDataTrigger>
								</ControlTemplate.Triggers>
					
							</ControlTemplate>
						</Setter.Value>
					</Setter>
					<!--<Style.Resources>
						<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
								Color="Transparent" />
						<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
								Color="Black" />
						<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
								Color="Transparent" />
					</Style.Resources>-->
				</Style>
			</TreeView.ItemContainerStyle>

		</TreeView>

	</DockPanel>

</UserControl>
